#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2020/8/14 23:42
# @Author : LZQ
# @Version：V 0.1
# @File : fastdfs_utils.py
# @desc :
from fdfs_client.client import get_tracker_conf, Fdfs_client
from PIL import Image
import base64
from PIL.PngImagePlugin import  PngImageFile
import io
class FDFS(object):
    conf_path = get_tracker_conf(r"D:\PycharmProjects\vue_shop\app\utils\client.conf")
    # 创建一个Fdfs_client对象
    client = Fdfs_client(conf_path)

    @classmethod
    def upload_by_buffer(cls,filebuffer):
        # 上传文件到fast dfs系统中，会返回一的字典
        res = cls.client.upload_by_buffer(filebuffer)
        # dict
        # {
        #     'Group name': group_name,
        #     'Remote file_id': remote_file_id,
        #     'Status': 'Upload successed.',   上传成功
        #     'Local file name': '',
        #     'Uploaded size': upload_size,
        #     'Storage IP': storage_ip
        # }
        return res

    @classmethod
    def download_by_fileId(cls,remote_file_id):
        res = cls.client.download_to_buffer(remote_file_id)
        return res

